package com.wanmei.service;


import com.wanmei.exception.WanmeiException;
import com.wanmei.mapper.AttributeMapper;
import com.wanmei.mapper.AttributevalueMapper;
import com.wanmei.mapper.CategoryMapper;
import com.wanmei.mapper.ProductMapper;
import com.wanmei.pojo.Attribute;
import com.wanmei.pojo.Exception_Msg;
import com.wanmei.pojo.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("AttributeService")
public class AttributeService {

    @Autowired
    private AttributeMapper attributeMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private AttributevalueMapper attributevalueMapper;

    /**
     * 通过产品的pid来找到cname 型号或者是大小规格
     *
     * @param pid
     * @return
     * @throws
     */
    public Attribute getAttributeAll(int pid) throws WanmeiException {
        Product product = productMapper.selectByPrimaryKey(pid);
        if (product == null) {
            throw new WanmeiException(Exception_Msg.ERROR_300002);
        }
            Attribute attribute = attributeMapper.getAttributeAllByCid(product.getCid());
        return attribute;
    }




}
